<!DOCTYPE html>  
<html>
<head>
	<meta charset="utf-8">
	<title>jsWaffle DEMO</title>
	<script type="text/javascript" src="jsWaffle.js"></script>
	<script type="text/javascript" src="res/demo-common.js"></script>
	<link rel="stylesheet" type="text/css" href="res/demo.css" />
	<script type="text/javascript">
		function init() {
			$("ver").innerHTML = "jsWaffle ver." + droid.getWaffleVersion();
			var disp = droid.getDisplayInfo();
			$("info").innerHTML = "Android ver." + droid.getAndroidVersionRelease() +
				" (" + disp.width + "x" + disp.height + "px)";
			droid.addEventListener("pause", function(){ droid.log("droid:pause") });
			droid.addEventListener("resume", function(){ droid.log("droid:resume"); });
			setMyMenuItem();
		}
	</script>
</head>
<body onload="init()">
	<h1>jsWaffle DEMO</h1>
	<div id="logo">
		<div style="text-align:center;">
			<img src="res/logo150.png" alt="jsWaffle LOGO" onclick="droid.vibrate()">
		</div>
		<div style="text-align:center;margin-bottom:8px;" id="ver"></div>
		<div style="text-align:center;margin-bottom:8px;" id="info"></div>
	</div>
	
	<!-- *** sample *** -->
	<h2>Beep/Ring/Vibrate</h2>
	<div class="buttons">
		<button onclick="droid.beep()">beep</button>
		<button onclick="check_ring()">ring</button>
		<button onclick="droid.vibrate()">vibrate</button>
		<button onclick="droid.makeToast('Hello!')">makeToast</button>
	</div>
	<script type="text/javascript">
		var ring_flag = false;
		function check_ring() {
			if (ring_flag == false) {
				droid.ring(); // ベルを鳴らす
				ring_flag = true;
			} else {
				droid.ring_stop(); // ベルを止める
				ring_flag = false;
			}
		}
	</script>
	
	<h2>Sound/Video</h2>	
	<div class="buttons">
		<button onclick="TestPlayer()">BGM:Play | Stop</button>
		<button onclick="TestSoundPool()">SE:Play SoundPool</button>
		<button onclick="droid.startIntent('http://www.youtube.com/watch?v=kbRBQ5c51eo')">Play Video(YouTube)</button>
	</div>
	<script type="text/javascript">
		// for SoundPool Test (ogg file)
		var soundId = droid.loadSoundPool("file:///android_asset/www/res/beep.ogg");
		function TestSoundPool() {
			droid.playSoundPool(soundId);
		}
		var playerObj = null;
		function TestPlayer() {
			if (playerObj == null) {
				playerObj = droid.playSound('www/res/beet.ogg', true);
			} else {
				if (droid.isPlayingSound(playerObj)) {
					droid.stopSound(playerObj);
				} 
				playerObj = null;
			}
			//droid.playSound('www/res/test.mp3');
		}
	</script>
	
	<h2>Maps</h2>
	<div class="buttons">
		<button onclick="droid.startIntent('geo:0,0?q=tokyo')">Map(Tokyo)</button>
		<button onclick="droid.showRoute('', '34.976002 138.383789')">showRoute</button>
	</div>
	
	<h2>Mail/Tel</h2>
	<div class="buttons">
		<button onclick="TestSendMail()">Send Mail</button>
		<button onclick="droid.startIntent('tel:117')">Call 117</button>
		<button onclick="TestContact()">Contact</button>
	</div>
	<script type="text/javascript">
		function TestSendMail() {
			droid.startIntent("mailto:web@kujirahand.com?subject=About_jsWaffle&body=test");
		}
		function TestContact() {
			droid.pickupContact(function(obj){
				if (obj == null) return;
				// alert(droid.stringify(obj));
				droid.startIntent("mailto:" + obj["email"] + "?subject=test");
			});
		}
	</script>
	
	<h2>HTTP</h2>
	<div class="buttons">
		<button onclick="droid.startIntent('http://d.aoikujira.com/android-app/jswaffle-ad.php')">Show Web Page</button>
		<button id="httpget_btn" onclick="testHTTP()">httpGet:Get IP</button>
		<button id="dl_btn" onclick="testHTTPDownload()">httpDownload:DL Image</button>
		<button id="post_btn" onclick="testHTTPPost()">httpPost:Get IP</button>
	</div>
	<script type="text/javascript">
		function testHTTP() {
			$("httpget_btn").disabled = true;
			droid.httpGet("http://api.aoikujira.com/ip/json",
				function(str){ alert(str); $("httpget_btn").disabled = false; }, 
				function(err){ alert(err); $("httpget_btn").disabled = false; }
			);
		}
		function testHTTPDownload() {
			$("dl_btn").disabled = true;
			droid.httpDownload(
				"http://d.aoikujira.com/jsWaffle/img/jsWaffle-icon300.png",
				"/sdcard/logo.png",
				function (status) {
					$("dl_btn").disabled = false;
					if (!status) { alert('download error'); return; }
					droid.startIntent("file:///sdcard/logo.png");
				}
			);
		}
		function testHTTPPost() {
			droid.httpPost("http://api.aoikujira.com/ip/get.php",
				{test:100, test2:150},
				function(result){
					alert(result);
				}
			);
		}
	</script>
	
	<h2>Snapshot</h2>
	<div class="buttons">
		<button onclick="showSnapshot()">Snapshot!!</button>
	</div>
	<script type="text/javascript">
		function showSnapshot() {
			droid.vibrate();
			var path = "file:///sdcard/test.png";
			droid.snapshotToFile(path, "png");
			setTimeout(
				function () {
					if (droid.fileExists(path)) {
						droid.startIntent(path);
					} else {
						alert("保存失敗!!");
					}
				}
			,500);
		}
	</script>
	
	<h2>Voice Recognizer</h2>
	<div class="buttons">
		<button onclick="startVoiceRecognizer()">VoiceRecognizer</button>
	</div>
	<script type="text/javascript">
		function startVoiceRecognizer() {
			droid.recognizeSpeech(function(n){
				alert(n);
			});
		}
	</script>
	
	<h2>More Samples</h2>
	<div class="buttons">
		<button onclick="location.href='test/dialogs.html'">Dialogs Sample</button>
		<button onclick="location.href='test/sensors.html'">Sensors Sample</button>
		<button onclick="location.href='test/storages.html'">Storages Sample</button>
		<button onclick="location.href='test/cameras.html'">Camera/Video Sample</button>
		<button id="flash_btn" disabled onclick="location.href='test-flash/test.html'">Flash Sample</button>
	</div>
	<script type="text/javascript">
		var ver = droid.getAndroidVersionInt();
		if (ver >= 8 /* android2.2 */) {
			$("flash_btn").disabled = false;
		}
	</script>
	<br/><br/><br/>

</body>
</html>